# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")

package(
    default_visibility = ["//visibility:public"],
    features = ["-ctad_warnings"],
)

licenses(["notice"])

cc_library(
    name = "base",
    hdrs = ["public/pw_allocator/bucket/base.h"],
    strip_include_prefix = "public",
    visibility = ["//visibility:private"],
    deps = [
        "//pw_allocator",
        "//pw_allocator:hardening",
        "//pw_allocator/block:poisonable",
        "//pw_assert:assert",
    ],
)

cc_library(
    name = "fast_sorted",
    hdrs = ["public/pw_allocator/bucket/fast_sorted.h"],
    features = ["-conversion_warnings"],
    strip_include_prefix = "public",
    deps = [
        ":base",
        "//pw_containers:intrusive_multimap",
    ],
)

cc_library(
    name = "sequenced",
    hdrs = ["public/pw_allocator/bucket/sequenced.h"],
    strip_include_prefix = "public",
    deps = [
        ":base",
        "//pw_containers:intrusive_list",
    ],
)

cc_library(
    name = "sorted",
    hdrs = ["public/pw_allocator/bucket/sorted.h"],
    strip_include_prefix = "public",
    deps = [
        ":base",
        "//pw_containers:intrusive_forward_list",
    ],
)

cc_library(
    name = "unordered",
    hdrs = ["public/pw_allocator/bucket/unordered.h"],
    strip_include_prefix = "public",
    deps = [
        ":base",
        "//pw_containers:intrusive_forward_list",
    ],
)

cc_library(
    name = "testing",
    testonly = True,
    hdrs = ["public/pw_allocator/bucket/testing.h"],
    strip_include_prefix = "public",
    tags = ["noclangtidy"],
    deps = [
        "//pw_allocator:buffer",
        "//pw_allocator:bump_allocator",
    ],
)

pw_cc_test(
    name = "fast_sorted_test",
    srcs = ["fast_sorted_test.cc"],
    features = ["-conversion_warnings"],
    deps = [
        ":fast_sorted",
        ":testing",
        "//pw_allocator/block:detailed_block",
    ],
)

pw_cc_test(
    name = "sequenced_test",
    srcs = ["sequenced_test.cc"],
    features = ["-conversion_warnings"],
    deps = [
        ":sequenced",
        ":testing",
        "//pw_allocator/block:detailed_block",
    ],
)

pw_cc_test(
    name = "sorted_test",
    srcs = ["sorted_test.cc"],
    features = ["-conversion_warnings"],
    deps = [
        ":sorted",
        ":testing",
        "//pw_allocator/block:detailed_block",
    ],
)

pw_cc_test(
    name = "unordered_test",
    srcs = ["unordered_test.cc"],
    features = ["-conversion_warnings"],
    deps = [
        ":testing",
        ":unordered",
        "//pw_allocator/block:detailed_block",
    ],
)

filegroup(
    name = "doxygen",
    srcs = [
        "public/pw_allocator/bucket/base.h",
        "public/pw_allocator/bucket/fast_sorted.h",
        "public/pw_allocator/bucket/sequenced.h",
        "public/pw_allocator/bucket/sorted.h",
        "public/pw_allocator/bucket/unordered.h",
    ],
)
